from flask import Blueprint, Flask
from view import  login, forget_password, register,\
    update_user_config,generate_study_plan,start_chat,\
    chat,get_history,delete_chat,search_chat,get_history_detail,save_note,search_note,delete_note,get_note,get_all_notes,update_note,translate_text,translate_file,generate_summary,get_user_config,upload_avatar

api_blueprint = Blueprint('/api/v1/', __name__, url_prefix='/api/v1/')

# 定义申请相关路由规则
rules = [
    {
        'rule': '/login',
        'endpoint': 'login',
        'view_func': login,
        'methods': ['POST']
    },
    {
        'rule': '/forget_password',
        'endpoint': 'forget_password',
        'view_func': forget_password,
        'methods': ['POST']
    },
    {
        'rule': '/register',
        'endpoint': 'register',
        'view_func': register,
        'methods': ['POST']
    },
    {
        'rule': '/user_configs',
        'endpoint': 'user_configs',
        'view_func': update_user_config,
        'methods': ['POST']
    },    {
        'rule': '/user/upload_avatar',
        'endpoint': 'upload_avatar',
        'view_func': upload_avatar,
        'methods': ['POST']
    },
    {
        'rule': '/user_config',
        'endpoint': 'user_config',
        'view_func': get_user_config,
        'methods': ['GET','POST']
    },
    {
        'rule': '/generate_study_plan',
        'endpoint': 'generate_study_plan',
        'view_func': generate_study_plan,
        'methods': ['POST']
    },
    {
        'rule': '/chat/start_chat',
        'endpoint': 'start_chat',
        'view_func': start_chat,
        'methods': ['GET','POST']
    },
    {
        'rule': '/chat/chat',
        'endpoint': 'chat',
        'view_func': chat,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/chat/histories',
        'endpoint': 'histories',
        'view_func': get_history,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/chat/history',
        'endpoint': 'history',
        'view_func': get_history_detail,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/chat/delete_chat',
        'endpoint': 'delete_chat',
        'view_func': delete_chat,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/chat/search_chat',
        'endpoint': 'search_chat',
        'view_func': search_chat,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/note/save',
        'endpoint': 'save',
        'view_func': save_note,
        'methods': ['POST']
    },
    {
        'rule': '/note/search',
        'endpoint': 'search',
        'view_func': search_note,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/note/delete',
        'endpoint': 'delete',
        'view_func': delete_note,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/note/generate',
        'endpoint': 'generate',
        'view_func': generate_summary,
        'methods': ['POST']
    },
    {
        'rule': '/note/get',
        'endpoint': 'get',
        'view_func': get_note,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/note/get_all',
        'endpoint': 'get_all',
        'view_func': get_all_notes,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/translate/translate',
        'endpoint': 'translate',
        'view_func': translate_text,
        'methods': ['GET', 'POST']
    },
    {
        'rule': '/translate/translate_file',
        'endpoint': 'translate_file',
        'view_func': translate_file,
        'methods': ['GET', 'POST']
    },

]

# 将申请相关路由规则添加到 Blueprint
for rule in rules:
    api_blueprint.add_url_rule(**rule)


def init_routes(app:Flask):
    app.register_blueprint(api_blueprint)
